package com.xiaozhen.data.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * @author zhenweisheng
 * @date 2020/9/30 8:49
 * @description:
 */
@Slf4j
@Configuration
@PropertySource("classpath:config/influxdb.properties")
public class InfluxDbConfig {

    @Value("${spring.influx.url}")
    private String influxDBUrl;

    @Value("${spring.influx.user}")
    private String userName;

    @Value("${spring.influx.password}")
    private String password;

    @Value("${spring.influx.database}")
    private String database;

    @Value("${spring.influx.days}")
    private String days;

    @Bean
    public InfluxDBConnect getInfluxDBConnect() {
        log.info("-=================================-indlucDbUrl:{}", influxDBUrl);
        log.info("-=================================-password:{}", password);
        log.info("-=================================-userName:{}", userName);
        log.info("-=================================-database:{}", database);
        InfluxDBConnect influxDB = new InfluxDBConnect(userName, password, influxDBUrl, database);
        influxDB.influxDbBuild();
        influxDB.createRetentionPolicy(days);
        return influxDB;
    }
}

